//
//  BYProductDetailsBannerCell.m
//  OCDemo
//
//  Created by zhumuzhi on 2022/1/5.
//

#import "BYProductDetailsBannerCell.h"
#import "SDCycleScrollView.h"

@interface BYProductDetailsBannerCell ()<SDCycleScrollViewDelegate>

@property (nonatomic, strong) SDCycleScrollView    *cycleScrollView;

@end


@implementation BYProductDetailsBannerCell

#pragma mark - SDCycleScrollViewDelegate

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index {
    
}

#pragma mark - CellHeight

+ (CGFloat)cellHeight {
    return kAutoWithSize(360) + kStatusBarHeight;
}

#pragma mark - SetData

- (void)setImages:(NSMutableArray *)images {
    _images = images;
    
    NSMutableArray *imageGroups = [NSMutableArray array];
    for (NSString *imageName in images) {
        NSString *imgPath = [NSString stringWithFormat:@"%@.png", imageName];
        [imageGroups addObject:imgPath];
    }
    self.cycleScrollView.localizationImageNamesGroup = imageGroups;
}

#pragma mark - Init
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView addSubview:self.cycleScrollView];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentView);
        make.top.equalTo(self.contentView).offset(kStatusBarHeight);
        make.height.mas_equalTo(kAutoWithSize(360));
    }];
}


#pragma mark - LazyGet

- (SDCycleScrollView *)cycleScrollView {
    if (_cycleScrollView == nil) {
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero imageNamesGroup:nil];
        _cycleScrollView.placeholderImage = [UIImage imageNamed:@"placeholder_general"];
        _cycleScrollView.backgroundColor = [UIColor whiteColor];
        _cycleScrollView.delegate = self;
        _cycleScrollView.infiniteLoop = YES;
        _cycleScrollView.autoScroll = YES;
        _cycleScrollView.showPageControl = YES;
        _cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
        _cycleScrollView.currentPageDotColor = PUBLIC_ORANGE_COLOR;
        _cycleScrollView.pageDotColor = [UIColor blackColor];
        _cycleScrollView.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    }
    return _cycleScrollView;
}

@end
